<template>
  <div>
    <!-- 近30天借阅数趋势图 -->
    <el-row>
      <el-col :span="24" style="padding: 5px">
        <el-card>
          <div id="main" style="width: 100%; height: 450px"></div>
        </el-card>
      </el-col>
    </el-row>

    <!-- 分类图书数量统计 -->
    <el-row>
      <el-col :span="24" style="padding: 5px">
        <el-card>
          <div id="pie1" style="width: 100%; height: 450px"></div>
        </el-card>
      </el-col>
    </el-row>

    <el-row>
      <!-- 图书借阅量统计 -->
      <el-col :span="24" style="padding: 5px">
        <el-card>
          <div id="pie2" style="width: 100%; height: 450px"></div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import * as echarts from 'echarts'

export default {
  name: "Home",
  data() {
    return {

    }
  },
  mounted() {  // 页面元素渲染之后再触发
    const option = {
      title: {
        text: '近30天图书借阅数趋势图',
        left: 'center'
      },
      tooltip: {
        trigger: 'item'
      },
      xAxis: {
        type: 'category',
        data: []
      },
      yAxis: {
        type: 'value'
      },
      series: [
        {
          data: [],
          type: 'line',
          smooth: true
        },
      ]
    };

    const pieOption1 = {
      title: {
        text: '分类图书数量统计',
        left: 'center'
      },
      tooltip: {
        trigger: 'item'
      },
      xAxis: {
        type: 'category',
        data: []
      },
      yAxis: {
        type: 'value'
      },
      series: [
        {
          data: [],
          type: 'bar'
        }
      ]
    };
    const pieOption2 = {
      title: {
        text: '图书借阅数量统计',
        left: 'center'
      },
      tooltip: {
        trigger: 'item'
      },
      legend: {
        orient: 'vertical',
        left: 'left'
      },
      series: [
        {
          type: 'pie',
          radius: ['40%', '60%'],
          avoidLabelOverlap: false,
          label: {
            show: false,
            position: 'center'
          },
          emphasis: {
            label: {
              show: true,
              fontSize: 40,
              fontWeight: 'bold'
            }
          },
          labelLine: {
            show: false
          },
          data: []
        }
      ]
    };

    // 折线图
    const  chartDom = document.getElementById('main');
    const  myChart = echarts.init(chartDom);
    this.$request.get("/borrow/borrowEcharts").then(res => {
      // 填空
      option.xAxis.data = res.data.x
      option.series[0].data = res.data.y
      // 数据准备完毕之后再set
      myChart.setOption(option);
    })

    // 饼图
    const  pieChartDom1 = document.getElementById('pie1');
    const  pieChart1 = echarts.init(pieChartDom1);
    this.$request.get("/book/bookCount").then(res => {
      // 填空
      pieOption1.xAxis.data = res.data.x
      pieOption1.series[0].data = res.data.y
      // 数据准备完毕之后再set
      pieChart1.setOption(pieOption1);
    })

    // 饼图
    const  pieChartDom2 = document.getElementById('pie2');
    const  pieChart2 = echarts.init(pieChartDom2);
    this.$request.get("/book/borrowCount").then(res => {
      // 填空
      pieOption2.series[0].data = res.data
      // 数据准备完毕之后再set
      pieChart2.setOption(pieOption2);
    })
  }
}
</script>

<style scoped>

</style>
